package config

import (
	"flag"
	"fmt"
	"os"
)

var (
	version string = "1.0"
)

func ParseArgs() (string, string, string) {
	listenAddr := flag.String("l", "", "listen address: :<port>")
	forwardAddr := flag.String("f", "", "forwarding address: <target ip:port>")
	configPath := flag.String("c", "", "config file path: e.x /home/go/config.yaml")
	flagVersion := flag.Bool("v", false, "print version")

	flag.Parse()

	if *flagVersion {
		fmt.Println("version:", version)
		os.Exit(0)
	}

	//if *forwardAddr == "" {
	//	flag.Usage()
	//	os.Exit(0)
	//}
	fmt.Printf("now listen port: %s, dial address: %s\n", *listenAddr, *forwardAddr)
	return *listenAddr, *forwardAddr, *configPath
}

func ParseArgsWithConfig(config *Config) (string, string) {
	listenAddr := flag.String("l", ":8080", "listen address: :<port>")
	forwardAddr := flag.String("f", "", "forwarding address: <target ip:port>")
	_ = flag.String("c", "", "config file path: e.x /home/go/config.yaml")
	flagVersion := flag.Bool("v", false, "print version")

	flag.Parse()

	if *flagVersion {
		fmt.Println("version:", version)
		os.Exit(0)
	}

	if *forwardAddr == "" {
		flag.Usage()
		os.Exit(0)
	}
	fmt.Printf("now listen port: %s, dial address: %s\n", *listenAddr, *forwardAddr)
	return *listenAddr, *forwardAddr
}
